package com.haiyou.dc.netty.chat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 启动netty服务器
 */
@Component
@Slf4j
public class NettyBootstrap implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private WsServer wsServer;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null) {
            try {
                wsServer.start();
            } catch (Exception ex) {
                log.error("---->启动失败:{}", ex);
            }
        }
    }
}
